package login

import (
	. "enca/module/db"
)

//用户信息
type UserInfo struct {
	Uid          string `json:"uid,omitempty" form:"uid" db:"uid"`
	Logintoken   string `json:"logintoken,omitempty" form:"logintoken" db:"logintoken"`
	UserName     string `json:"userName,omitempty" form:"user_name" db:"user_name"`
	UserAccount  string `json:"userAccount,omitempty" form:"user_account" db:"user_account"`
	UserPassword string `json:"userPassword,omitempty" form:"user_password" db:"user_password"`
	UserPhone    string `json:"userPhone,omitempty" form:"user_phone" db:"user_phone"`
	UserAvatar   string `json:"userAvatar,omitempty" form:"user_avatar" db:"user_avatar"`
}

//错误
func checkErr(err error) {
	if err != nil {
		panic(err)
	}
}

func Login(userAccount string, userPassword string) (code int, data interface{}) {
	var userInfo []UserInfo

	err := Db.Select(&userInfo, "SELECT uid, user_name, user_account, user_phone, user_avatar FROM user_list WHERE user_account='"+userAccount+"' and user_password='"+userPassword+"'")
	checkErr(err)

	if len(userInfo) > 0 {
		code = 200
		data = userInfo
	} else {
		code = 500
		data = "用户名或密码输入错误"
	}

	return
}
